package com.ymatou.iapi.productmanager.testcase;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.BrandDto;
import com.ymatou.iapi.productmanager.parameter.CategoryDto;
import com.ymatou.iapi.productmanager.parameter.GetBrandsBean;
import com.ymatou.iapi.productmanager.parameter.GetCategorysBean;
import com.ymatou.iapi.productmanager.service.GetBrandsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取买手所有的商品品牌
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetBrands{
	private static GetBrandsBean getbrandsBean;
	private static GetBrandsCall getbrandsCall;
	private static Integer userId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手所有的商品品牌");
	}

	@Before
	public void caseUp() {
		getbrandsBean=new GetBrandsBean();
		getbrandsCall=new GetBrandsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbrandsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBrands_001() {
		Logger.start(true,"获取买手所有的商品品牌");
		try {
			getbrandsBean.setUserId(userId);
			getbrandsCall.setData(getbrandsBean);
			checkBrands(userId,getbrandsBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBrands_002() {
		Logger.start(true,"获取买手所有的商品品牌,不传userid");
		try {
			getbrandsCall.setData(getbrandsBean);
			getbrandsCall.callService();
			//checkBrands(userId,getbrandsBean);
			Logger.verifyEquals("400", getbrandsCall.getString("Code"), "买手Id不能为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public void checkBrands(Integer userId,GetBrandsBean getbrandsBean) throws InterruptedException, ClientProtocolException, IOException{
		getbrandsCall.callService();
		Logger.verifyEquals("200", getbrandsCall.getString("Code"), "验证Code");
		List<BrandDto> brands = getbrandsCall.getBrands();
		List<Map> sbrands = new YmtProductsIWapper().getBrands(userId);
		Logger.debug(sbrands);
		for(int i = 0;i < sbrands.size();i++){
			if((Integer)sbrands.get(i).get("iBrandId")==brands.get(i).getBrandId()){
				Logger.verifyEquals(brands.get(i).getBrandEName(), sbrands.get(i).get("sBrandEn").toString(), "验证BrandNameEn");
				Logger.verifyEquals(brands.get(i).getBrandName(), sbrands.get(i).get("sBrand").toString(), "验证BrandName");
			}
		}
	}
}